package com.feri.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feri.api.dao.MoodtypeDao;
import com.feri.api.service.intf.MoodService;
import com.feri.api.service.intf.MoodtypeService;
import com.feri.api.util.BaiduCensorUtil;
import com.feri.api.util.TokenUtil;
import com.feri.api.vo.R;
import com.feri.common.entity.Car;
import com.feri.common.entity.Moodtype;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @author lr
 * @date 2022/10/3
 */
@Service
public class MoodtypeServiceImpl implements MoodtypeService {
    @Resource
    private MoodtypeDao dao;
    @Override
    public R save(String name,String token) {
        Long aLong = TokenUtil.toLong(token);
        if (StringUtils.hasLength(name)&& aLong>0l){
             if (BaiduCensorUtil.textCensor(name)){
                if (dao.insert(new Moodtype(aLong,name))>0){
                    return R.ok();
                }
             }else {
                 return R.fail("您输入的内容包含敏感词 请重新输入");
             }
        }
        return R.fail();
    }

    @Override
    public R queryAll() {
        return R.ok(dao.selectList(null));
    }

    @Override
    public R detale(Integer id, String token) {
        Long aLong = TokenUtil.toLong(token);
        if (aLong>0L){
            if (dao.selectOne(new QueryWrapper<Moodtype>().eq("id",id).eq("uid",aLong))!=null){
                if (dao.deleteById(id)>0){
                    return R.ok();
                }
            }
        }

        return R.fail();
    }
}
